﻿@model AdminUserDTO
@{
    ViewBag.Title = "ChangePwd";
    Layout = null;
}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>个人信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="~/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="~/common/bootstrap/css/bootstrap.css" media="all">
    <link rel="stylesheet" type="text/css" href="~/common/global.css" media="all">
    <link rel="stylesheet" type="text/css" href="~/css/personal.css" media="all">
</head>
<body>
    <section class="layui-larry-box">
        <div class="larry-personal">
            <header class="larry-personal-tit">
                <span>修改密码</span>
            </header><!-- /header -->
            <div class="larry-personal-body clearfix changepwd">
                <form class="layui-form col-lg-4" id="form">
                    <input type="hidden" name="Id" value="@Model.Id" />
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-block">
                            <input type="text" autocomplete="off" class="layui-input layui-disabled" value="@Model.Name" disabled="disabled">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">新密码</label>
                        <div class="layui-input-block">
                            <input type="password" lay-verify="pass" id="NewPassWord" name="NewPassWord" autocomplete="off" class="layui-input" value="" placeholder="请输入新密码">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">确认密码</label>
                        <div class="layui-input-block">
                            <input type="password" lay-verify="OkPwd" name="IsNewPassWord" autocomplete="off" class="layui-input" value="" placeholder="请输入确认新密码">
                        </div>
                    </div>
                    <div class="layui-form-item change-submit">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </section>
    <script type="text/javascript" src="~/common/layui/layui.js"></script>
    <script src="~/js/jquery-3.2.1.js"></script>
    <script type="text/javascript">
        layui.use('form', function () {
            var form = layui.form();

            form.on('submit(demo1)', function (data) {
                var json = $('#form').serialize();
                $.ajax({
                    url: "/Main/ChangePwd",
                    data: json,
                    dataType: "json",
                    type: "post",
                    success: function (res) {
                        if (res.status == "ok") {
                            layer.msg("修改成功", { icon: 1, time: 1500 });
                            
                            //parent.location.reload();
                        } else if (res.status == "redirect") {
                            location.href = res.msg;
                        } else if (res.status == "error") {
                            layer.msg(res.errorMsg, { time: 1000, icon: 1 });
                        } else {
                            layer.msg("错误", { time: 1000, icon: 2 });
                        }
                    }, error: function () {
                        layer.msg("请求出错", {icon:2,time:1000});
                    }
                });

                return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
            });
            form.verify({
                OkPwd: function (value, item) { //value：表单的值、item：表单的DOM对象
                    if ($('#NewPassWord').val()!=value) {
                        return '两次输入的密码不一致';
                    }
                },
                pass: [
                    /^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'
                ]
            });

        });
    </script>
</body>
</html>
